<%! import cgi %>
<%inherit file="base.html"/>
<h2>
    ${profile_fields['generic']['name']['values'][0]['value']}
    <span class="inlineNav">
        <a href="#updates">${_('Updates')}</a>
        <a href="#mycontent">${_('Content')}</a>
        <a href="#members">${_('Members')}</a>
    </span>
</h2>
% if is_member:
    <span class="tag member">${_('Member')}</span>
% endif
<div class="lastUpdated">
    ${_('Updated:')} ${profile_fields['meta']['pretty_last_updated']}
</div>
<div id="leftPanel">
    <div class="pictureWrapper">
        % if is_admin and profile_fields['generic']['picture']['is_dummy']:
            <a title="${_('Click to edit image')}" href="http://${hexlabel}.hexlabel.net/group/edit_picture/">
        % elif not profile_fields['generic']['picture']['is_dummy']:
            <a title="${_('Click to view original image')}" href="${profile_fields['generic']['picture']['values'][0]['value']}">
        % endif
            <img src="${profile_fields['generic']['picture']['values'][0]['value']}" alt="${_('Profile picture')}"/>
        </a>
        % if is_admin:
            <a href="/group/edit_picture" class="admin">${_('Edit')}</a>
        % endif
    </div>
</div>
<div id="mainPanel">
    <div class="section" id="description">
        % if profile_fields['generic']['about']['values'][0]['value']:
            <p><% nl2br(profile_fields['generic']['about']['values'][0]['value']) %></p>
            % if is_admin:
                <a href="/group/edit" class="admin">${_('Edit')}</a>
            % endif
        % elif is_admin:
            <p>${_('No description has been entered.<br/>(Only group admins will see this message)') | n}</p>
            <a href="/group/edit" class="admin">${_('Edit')}</a>
        % endif
        <div class="clr"><br/></div>
    </div>

    <div class="section" id="updates">
        <h3>
            ${_('Updates')}
            <span class="inlineNav">
                <!--
                <a href="#wrapper">^ ${_('Top')}</a>
                -->
            </span>
        </h3>
        % if len(events_list['items']) > 0:
            <ul>
                % for event in events_list['items'][:4]:
                    <li>
                        ${event['comment']}
                        % if event['target_iid']:
                         : <a href="http://${event['target_iid']}.hexlabel.net/">${event['target_name']}</a>
                        % endif
                    </li>
                % endfor
            </ul>
        % else:
            <p>${_('Nothing new.')}</p>
        % endif

        % if len(atom_list['items']) > 0:
            <ul class="atomList">
                % for direct_content in [True, False]:
                    % for feed in atom_list['items']:
                        % if len(feed['entries']) > 0:
                            % if (direct_content and feed['parent']['iid'] == hexlabel) or (not direct_content and feed['parent']['iid'] != hexlabel):
                                <li class="feed">
                                    <h4>${('New content in')} <a href="http://${feed['id']}.hexlabel.net/">${feed['title']}</a></h4>
                                    % if feed['parent']['iid'] != hexlabel:
                                    <div class="parentInfo">Linked from <a href="http://${feed['parent']['iid']}.hexlabel.net">${feed['parent']['name']}</a></div>
                                    % endif
                                    % for entry in feed['entries']:
                                        % if entry.has_key('link'):
                                            % if entry['link'].get('type') and entry['link']['type'].startswith('image/'):
                                                <p class="inline">
                                                    <img src="${entry['link']['href']}" width="32" height="32" alt=""/>
                                                </p>
                                            % else:
                                                <p class="inline">
                                                    <a href="${entry['link']['href']}">${entry['title']}</a>
                                                </p>
                                            % endif
                                        % else:
                                            % if entry['title']:
                                                <h5>${entry['title']}</h5>
                                            % endif
                                            <p class="entry">
                                                ${entry['summary']}
                                            </p>
                                            <div class="metadata">
                                                <p class="author"><a href="${entry['author']['uri']}">${entry['author']['name']}</a></p>
                                                <p class="updated">${entry['pretty_updated']}</p>
                                            </div>
                                        % endif
                                    % endfor
                                    <div class="clr"><br/></div>
                                </li>
                            % endif
                        % endif
                    % endfor
                % endfor
            </ul>
        % endif
    </div>

    <div class="section" id="mycontent">
        <h3>
            ${_('Content')}
            <span class="inlineNav">
                % if is_admin:
                    <a href="http://admin.hexlabel.net/group_content/?iid=${hexlabel}" class="admin">${_('Manage...')}</a>
                % endif
                <!--
                <a href="#wrapper">^ ${_('Top')}</a>
                -->
            </span>
        </h3>
        % if content_list['index']:
            <ul>
                % for ciid in content_list['index']:
                    % if content_list['items'][ciid]['stable']:
                        <li>
                            <a href="http://${ciid}.hexlabel.net">
                                <img src="${content_list['items'][ciid]['picture']}" class="thumbnail" alt=""/>
                            </a>
                            <a href="http://${ciid}.hexlabel.net">${content_list['items'][ciid]['title']}</a>
                            <div class="roles">
                                % if not content_list['items'][ciid]['visibility']:
                                    <span class="restricted">${_('Members only')}</span>
                                % endif
                            </div>
                        </li>
                    % else:
                        <li class="unstable">
                            <a href="http://${ciid}.hexlabel.net">
                                <img src="${content_list['items'][ciid]['picture']}" class="thumbnail" alt=""/>
                            </a>
                            <a href="http://${ciid}.hexlabel.net">${content_list['items'][ciid]['title']}</a>
                            <p>${_('This data is not available at the moment...')}</p>
                        </li>
                    % endif
                % endfor
            </ul>
        % else:
            <ul>
                <li>${_('No content.')}</li>
            </ul>
        % endif
    </div>

    <div class="section" id="members">
        <h3>
            ${_('Members')} (${len(member_list['index'])})
            <span class="inlineNav">
                % if is_member:
                    <a href="http://admin.hexlabel.net/invite_group/?iid=${hexlabel}" class="admin">${_('Invite...')}</a>
                % endif
                % if is_admin:
                    <a href="http://admin.hexlabel.net/manage_group/?iid=${hexlabel}#members" class="admin">${_('Manage...')}</a>
                % endif
                <!--
                <a href="#wrapper">^ ${_('Top')}</a>
                -->
            </span>
        </h3>
        % if len(member_list['index']) > 0:
            <ul>
                % for miid in member_list['index']:
                    <li>
                        <a href="http://${miid}.hexlabel.net/">
                            <img src="${member_list['items'][miid]['picture']}" alt="${member_list['items'][miid]['name']}" class="thumbnail"/>
                        
                        </a>
                        <a href="http://${miid}.hexlabel.net/">${member_list['items'][miid]['name']}</a>
                        <div class="roles">
                            % if 'admin' in member_list['items'][miid]['roles']:
                                <div class="role"><span class="admin">${_('Admin')}</span></div>
                            % elif 'author' in member_list['items'][miid]['roles']:
                                <div class="role"><span class="author">${_('Author')}</span></div>
                            % endif
                            % if member_list['items'][miid]['is_self']:
                                <div class="role"><span class="self">${_('You')}</span></div>
                            % endif
                            % if member_list['items'][miid]['is_friend']:
                                <div class="role"><span class="friend">${_('Friend')}</span></div>
                            % endif
                        </div>
                    </li>
                % endfor
            </ul>
        % else:
            <ul>
                <li>${_('No members.')}</li>
            </ul>
        % endif
    </div>
</div>


<!-- defs -->
<%def name="head()"></%def>
<%def name="title()">P2P Fusion - Peerscape | ${profile_fields['generic']['name']['values'][0]['value']}</%def>
<%def name="body_class()">
    % if is_member:
  	    profile group member
    % else:
  	    profile group
    % endif
</%def>

<%def name="notifications()">
    % if invitations.has_key(hexlabel):
        <div class="item">
            <form method="post" action="http://${my_iid}.hexlabel.net/person/" class="listForm">
                <input type="hidden" name="invitation_iid" value="${hexlabel}"/>
                <dl>
                    <dd>You have a pending membership invitation from this group.</dd>
                    <dd class="buttons">
                        <input type="submit" class="submit" name="invitation_decline" value="Decline"/>
                        <input type="submit" class="submit default" name="invitation_accept" value="Accept"/>
                    </dd>
                </dl>
                <div class="clr"><br/></div>
            </form>
        </div>
    % endif
    % if is_member and visibility and False:
        <div class="item">
            <p>You have a public link to this group on your profile.</p>
            <p><a href="http://admin.hexlabel.net/manage_group/?iid=${hexlabel}#visibility">Change</a></p>
        </div>
    % endif
</%def>

<%def name="nl2br(s)">
    ${'<br/>'.join(cgi.escape(s).split("\n")) | n}
</%def>
